//
//  GKTabBarController.swift
//  MicroBlogFunc
//
//  Created by GK on 16/4/8.
//  Copyright © 2016年 GK. All rights reserved.
//

import UIKit

class GKTabBarController: UITabBarController {

    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        let mainBar = GKTabBar()
        
        //加号按钮回调
        mainBar.composeClosure = {
            print("加号被点击了")
        }
        //kvc:tabBar是只读的(getonly),不能直接赋值,只能通过kvc
        setValue(mainBar, forKey: "tabBar")
        
        
        self.addChildControllers()
    }

    //添加子控制器
    private func addChildControllers()
    {
        addAChildController(GKHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addAChildController(GKMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addAChildController(GKDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addAChildController(GKProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    //添加一个子控制器
    private func addAChildController(controller: UIViewController ,imageName: String, title: String)
    {
        let childVC = controller
        childVC.tabBarItem.image = UIImage(named: imageName)
        childVC.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        childVC.title = title
        let navVC = UINavigationController(rootViewController: childVC)
        self.addChildViewController(navVC)
    }
    
    
    
    

}
